<?php
include('includes/connection_settings.php');


//Strips " and ' marks
$bannedMarks = array("\"", "'");

$_GET['user'] = str_replace($bannedMarks, "", $_GET['user']);


echo "<h1>User {$_GET['user']}</h1>";

//How many words
$table = mysql_query("SELECT COUNT(*) FROM words WHERE creator = '{$_GET['user']}'");
if (!isset($table)) {
 echo "<h1>Can't choose data from the table!</h1><p>" . mysql_error($connection) . "</p>";
 exit;
}

echo "<p>Has added " . mysql_result($table, 0, 0) . " words</p>";

//Sums all points of the user
$table = mysql_query("SELECT SUM(points_{$_GET['user']}) FROM words");
if (!isset($table)) {
 echo "<h1>Can't choose data from the table!</h1><p>" . mysql_error($connection) . "</p>";
 exit;
}
$summedPoints = mysql_result($table, 0, 0);

//How many word pairs aka lines
$tableRowCount = mysql_query("SELECT * FROM words");
if (!isset($table)) {
 echo "<h1>Can't choose data from the table!</h1><p>" . mysql_error($connection) . "</p>";
 exit;
}

$roundedAverage = round($summedPoints / mysql_num_rows($tableRowCount), 3);

echo "<p>Progress of the user is " . $roundedAverage * 20 . "%</p>";

?>